﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace MechAddin.Command.移动零件
{
    /// <summary>
    /// 移动零件View.xaml 的交互逻辑
    /// </summary>
    public partial class 移动零件View : Window
    {
        static string TextValue { get; set; }
        移动零件ViewModel VM { get; set; }
        public 移动零件View()
        {
            InitializeComponent();
            VM = new 移动零件ViewModel();
            DataContext = VM;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Dis.Focus();
            Dis.Text = TextValue;
            Dis.SelectAll();
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            Run();
        }


        private void Run()
        {
            TextValue = VM.Dis;
            VM.Run();
            VM = null;
            this.Close();
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Run();
                this.Close();
            }
            else if (e.Key == Key.Escape)
            {
                this.Close();
            }
        }

        private void Dis_TextChanged(object sender, TextChangedEventArgs e)
        {
            VM.Dis = Dis.Text;
        }
    }
}
